package hanjia;

import java.util.Arrays;

/**
 * Description:
 * Author:    Dane
 * CreateTime:2025/2/17-下午2:28
 * Since  :   1.0
 * Version:   1.0
 */
public class LeetCode135 {

    public int candy(int[] ratings) {
        if (ratings.length == 1) {
            return 1;
        }
        int[] result = new int[ratings.length];
        Arrays.fill(result,1);
        for (int i=1;i<ratings.length;i++){
            if (ratings[i]>ratings[i-1]){
                result[i]=result[i-1]+1;
            }
        }
        for (int i=ratings.length-2;i>=0;i--){
            if (ratings[i]>ratings[i+1]){
                int temp=result[i+1]+1;
                result[i]=Math.max(result[i],temp);
            }



        }
        int sum=0;
        for (int i:result){
            sum+=i;
        }
        return sum;






    }

}
